#include "stdafx.h"
#include "DB/DBConnection.h"
#include "mysql++.h"

bool DBConnection::init( const char* pAddress,const char* pUser,const char* pPassWord,const char* pDBName )
{
DB_TRY
	m_connection = new mysqlpp::TCPConnection();
	m_connection->connect(pAddress,pDBName,pUser,pPassWord);
	m_workqueue.Start(1);
DB_CATCH(return false;)
	return true;
}
void DBConnection::cleanup()
{
	m_connection->disconnect();
	SAFE_DELETE(m_connection);
}
void DBConnection::asynQuery( mysqlpp::Query& _query ,AsynDB_CallBack* pCallBack)
{
	DBQueryItem* pItem = new DBQueryItem(m_connection,_query,pCallBack);
	m_workqueue.PushWorkItem(pItem);
}

void DBConnection::asynQuery( mysqlpp::Query& _query,AsynDB_CallBack* pCallBack,const mysqlpp::SQLQueryParms& str )
{
	DBTemplateQuery* pItem = new DBTemplateQuery(m_connection,_query,pCallBack,str);
	m_workqueue.PushWorkItem(pItem);
}

mysqlpp::Query DBConnection::getQuery()
{
	return m_connection->query();
}
